import Taro from "@/newTaro";
import store from "@/store";
import { setSystemInfos } from "@/store/actions/common";

export function getSystemInfos() {
	Taro.getSystemInfo({
		success: function (res) {
			let rect = Taro.getMenuButtonBoundingClientRect();
			let CustomBarHeight = 0; // 自定义导航栏高度
			let TitleBarHeight = 0; // 标题栏高度
			if (res.system.toLowerCase().indexOf("ios") > -1) {
				//IOS
				CustomBarHeight = res.statusBarHeight + rect.height + (rect.top - res.statusBarHeight) * 2;
				TitleBarHeight = CustomBarHeight - res.statusBarHeight;
			} else {
				//安卓
				TitleBarHeight = rect.height + (rect.top - res.statusBarHeight) * 2;
				CustomBarHeight = TitleBarHeight + res.statusBarHeight;
			}
			console.log('getSystemInfo',TitleBarHeight,CustomBarHeight)
			// todo yc 获取到参数应该将参数存储在全局参数中
			// store.dispatch(
			// 	setSystemInfos({
			// 		...res,
			// 		TitleBarHeight,
			// 		CustomBarHeight
			// 	})
			// );
		}
	});
};

// 封装的跳转分包的路由写法

export function navigateTo(url, param) {
	let newUrl = url;
	console.log('navigateTo',url,param);
	if (param) {
		newUrl = `${url}?param=${JSON.stringify(param)}`;
	}
	Taro.navigateTo({
		url: newUrl,
		fail(_res) {
			Taro.redirectTo({
				url: newUrl
			});
		}
	});
}
